package com.lj.demo.eduservice.controller.front;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lj.demo.commonutils.R;
import com.lj.demo.eduservice.entity.EduCourse;
import com.lj.demo.eduservice.entity.EduTeacher;
import com.lj.demo.eduservice.entity.vo.CourseQueryVo;
import com.lj.demo.eduservice.service.EduCourseService;
import com.lj.demo.eduservice.service.EduTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: liujiang
 * @Date: 2020/12/28/13:51
 * @Description:
 */
@Api(description = "前台讲师页面")
@RequestMapping("/eduservice/teacherFront")
@RestController
@CrossOrigin
public class TeacherFrontController {
    @Autowired
    private EduTeacherService teacherService;

    @Autowired
    private EduCourseService courseService;

    @ApiOperation(value = "分页查询讲师列表")
    @GetMapping("/pageList/{page}/{limit}")
    public R pageList(@PathVariable Long page,
                      @PathVariable Long limit){
        Page<EduTeacher> pageTeacher = new Page(page,limit);
        Map<String,Object> map = teacherService.getPageList(pageTeacher);
        return R.ok().data(map);
    }

    @ApiOperation(value = "根据讲师查询id")
    @GetMapping("getById/{id}")
    public R getById(@PathVariable String id){
        //查询讲师信息
        EduTeacher teacher = teacherService.getById(id);

        //根据讲师查询课程列表
       List<EduCourse> courses = courseService.getCourseList(id);
       return R.ok().data("teacher",teacher).data("course",courses);
    }

    @ApiOperation(value = "根据条件分页查询课程列表")
    @PostMapping("/pageCourseList/{page}/{limit}")
    public R pageCourseList(@PathVariable Long page,
                            @PathVariable Long limit,
                            @RequestBody(required = false)CourseQueryVo courseQueryVo){
        Page<EduCourse> pageCourse = new Page<>(page,limit);
        Map<String,Object> map = courseService.getCourseWeb(pageCourse,courseQueryVo);
        return R.ok().data(map);
    }


}
